﻿using _13Net8AspNetCore_AuthorizationAuthentication.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace _13Net8AspNetCore_AuthorizationAuthentication.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        /// <summary>
        /// 获得产品
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<Product> GetProduct()
        {
            Product product = new Product() { ID = 1, Name = "鉴权" };
            return product;

        }

        /// <summary>
        /// 查询商品
        /// </summary>
        /// <returns></returns>
        [Authorize("UserName")]
        [HttpGet("GetProduct2")]
        public async Task<Product> GetProduct2()
        {
            Product product = new Product() { ID = 1, Name = "鉴权" };
            return product;
        }

        /// <summary>
        /// 查询商品
        /// </summary>
        /// <returns></returns>
        [Authorize("Password")]
        [HttpGet("Password")]
        public async Task<Product> GetProductPassword()
        {
            Product product = new Product() { ID = 1, Name = "鉴权" };
            return product;
        }
    }
}
